package fun.wlfj.dbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class MySQLConnection implements IConnectionManager {
	//我们要实现数据库链接的获取和关闭
	Connection conn = null;
	public MySQLConnection() {
		try {
			Class.forName("com.mysql.cj.jdbc.Driver");
			//QAQ
			conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/cash_db", "root", "123");
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			System.out.println("驱动加载失败！");
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			System.out.println("数据库连接失败！");
			e.printStackTrace();
		}
	}
	
	public Connection getConn() {
		return conn;
	}
	
	public void closeAll(PreparedStatement pstsm) {
		IConnectionManager.closePstsm(pstsm);
		if(conn != null) {
			try {
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	public static void main(String[] args) {
		MySQLConnection connection = new MySQLConnection();
		
	}
}
